
$(function () {
	var prizeId = $("#prizeId").val();
	var shippingType = $("#shippingMethod_hidden").val();//配送方式
	var type_hidden = $("#type_hidden").val();//奖品类型
	
	//页面加载时设置配送方式
	$("#shippingMethod").val(shippingType);
	$("#type").val(type_hidden);
	
	if(type_hidden == 1 ||type_hidden == 3){
		var autoOptions = "<option value='1'>自动发送</option>";
		$("[name='shippingMethod']").append(autoOptions);
		$('#site').hide();
		$('#selectedProDiv').hide();
		
		
	}else if(type_hidden == 2){
		if(shippingType ==2){
			var autoOptions = "<option value='2' selected>上门自提</option><option value='3'>物流配送</option>";
			$("[name='shippingMethod']").append(autoOptions);
		}else if(shippingType == 3){
			var autoOptions = "<option value='2'>上门自提</option><option value='3' selected>物流配送</option>";
			$("[name='shippingMethod']").append(autoOptions);
		}
	}
	
	if(shippingType == 3){
		$('#site').hide();
		$('#selectedProDiv').hide();
	}
	
	
	//取消奖品
	$("[name='btn_cancel_edit_prize']").click(function(){
		window.location.href="/prize";
	});
	
   
    
    
    //删除已选择的网点
    /*$("[name='btn_delete_prize_branch']").click(function(){
    	var branchId = $(this).data("prize-branch-id");
    	
        bootbox.bconfirm("确定要删除这个网点吗？", function (re) {
            if (re) {
                $.delete("/prize/delBranch/" + branchId, function (re) {
                    if (re.data) {
                        // tipper.success("删除成功，请刷新页面");
                        window.location.href="/prize?prizeId=" + prizeId;
                    } else {
                        //tipper.danger("删除失败，请重试");
                    }
                });
            }
        });
    });*/
    
  //加载已存在的奖品图片
	$("#ctn_edit_product_pics").empty();
    if ($("#image").val()) {
        var pictures = $("#image").val().split(",");
        for (var i in pictures) {
            var uri = pictures[i];
            if (/.+/.test(uri)) {
                var $imgEle = $("<img src='" + PicDomain + uri + "' data-picuri='" + uri + "'/>");
                $imgEle.click(function () {
                	var self = this;
                	bootbox.bconfirm("确定要删除奖品图片吗？", function (re) {
    					if(re){
    						$(self).remove();
    					}
                	});
                	/*$(this).remove();*/
                });
                $("#ctn_edit_product_pics").append($imgEle);
            }
        }
    }
    
});
    

   


